Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getDirectoryContents' which ignores "." and ".." #36

Merged
merged 3 commits into from
Oct 3, 2015

Conversation

guibou
Copy link
Contributor

@guibou guibou commented Sep 25, 2015

getDirectoryContents returns the "." and ".." special directories. However in most cases user do not care about theses values and must manually filter them. This pull request introduces the getDirectoryContents' variant which handle this filtering. I find this really convenient when working with directory listing. Other languages uses the same trick (such as python, with os.listdir(),

Discussion: should we update removeContentsRecursive to use getDirectoryContents' instead of the explicit manual filtering of "." and ".." ?

@Rufflewind
Copy link
Member

Perhaps instead of using a prime (which may be confused for other things), we could call it getDirectoryContentsA to mirror the -A flag for ls. I was originally thinking of getDirectoryContentsPlain but the name is already too long.

should we update removeContentsRecursive to use getDirectoryContents' instead of the explicit manual filtering of "." and ".." ?

I don't see any reason not to :P

Thanks for the pull request!

@guibou
Copy link
Contributor Author

guibou commented Sep 26, 2015

Thank you for your reply. I will amend the pull request to change the name to getDirectoryContentsA, you are right that the prime is confusing, I initially saw it as an alternate version, but apparently it is commonly used for strict version of a function.

I also edited removeContentsRecursive to use the new getDirectoryContentsA. My last question is about the unit tests. For now there is 29 tests which introduce a use of getDirectoryContents (and a special handling of . and ..).

For the sake of simplifing the unit test, should we edit them to use getDirectoryContentsA in most cases ?

@guibou
Copy link
Contributor Author

guibou commented Sep 26, 2015

I amended the initial commit to change the name to getDirectoryContentsA, updated removeContentsRecursive to use it, and updated tests to use getDirectoryContentsA when it simplifies the tests.

@Rufflewind
Copy link
Member

updated tests to use getDirectoryContentsA when it simplifies the tests.

While that's fine for the other tests, for tests/GetDirContents001.hs it's best to leave both getDirectoryContents and getDirectoryContentsA in to ensure that getDirectoryContents is covered by at least one test (to prevent a future change from accidentally removing . and .. from getDirectoryContents).

@Rufflewind Rufflewind merged commit 0e7e7a3 into haskell:master Oct 3, 2015
@guibou
Copy link
Contributor Author

guibou commented Oct 3, 2015

Thank you for merging it. Sorry I did not answer your complain about the unit test not covering . and .. for getDirectoryContents (I was busy this week...).

I'll soon do another pull request to fix that (an some other stuff if time is available).

@Rufflewind
Copy link
Member

I'll soon do another pull request to fix that

Don't worry about that – it's all taken care of. Thanks for your contribution!

@Rufflewind
Copy link
Member

Just a heads up in case you happen to be using HEAD: I've renamed getDirectoryContentsA to listDirectory.

bgamari pushed a commit to bgamari/directory that referenced this pull request Jul 29, 2016
Remove double quotes around searchPath elements on Windows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants